package com.diandian.backend.dingding.data.controller;

import com.diandian.backend.dingding.data.service.DingdingStaffSalaryService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.base.boot.starter.util.ResultUtil;
import com.diandian.backend.dingding.data.param.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * [钉钉]员工薪资表
 */
@RestController
@RequestMapping("/staff/salary")
public class DingdingStaffSalaryController {

    @Autowired
    private DingdingStaffSalaryService iDingdingStaffSalaryService;

    /**
    * 分页查询 todo
    */
    @PostMapping("/page")
    public BaseResult page(@RequestBody DingdingStaffSalaryPageParam param) {
        param.check();
        return ResultUtil.makeResult(iDingdingStaffSalaryService.page(param.toDTO()));
    }

    /**
     * 查询详情 todo
     */
    @PostMapping("/detail")
    public BaseResult getDetail(@RequestBody DingdingStaffSalaryDetailParam param) {
        return ResultUtil.makeResult(iDingdingStaffSalaryService.getDetail(param.toDTO()));
    }

    /**
     * 根据数据id更新数据 todo
     */
    @PostMapping("/updateById")
    public BaseResult updateById(@RequestBody DingdingStaffSalaryUpdateByIdParam param) {
        iDingdingStaffSalaryService.updateById(param.toDTO());
        return ResultUtil.makeResult();
    }

    /**
     * 根据数据id删除数据 todo
     */
    @PostMapping("/deleteById")
    public BaseResult deleteById(@RequestBody DingdingStaffSalaryDeleteByIdParam param) {
        param.check();
        iDingdingStaffSalaryService.deleteById(param.toDTO());
        return ResultUtil.makeResult();
    }

    /**
     * 新增 todo
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody DingdingStaffSalaryAddParam param) {
        iDingdingStaffSalaryService.add(param.toDTO());
        return ResultUtil.makeResult();
    }

    /**
     * 列表查询 todo
     */
    @PostMapping("/list")
    public BaseResult list(@RequestBody DingdingStaffSalaryListParam param) {
        return ResultUtil.makeResult(iDingdingStaffSalaryService.getList(param.toDTO()));
    }

    /**
     * 导入月工资
     * @param file
     * @param belong
     * @return
     * @throws Exception
     */
    @PostMapping("/import")
    public BaseResult importMonthSalary(MultipartFile file, @RequestParam(value = "belong") String belong, @RequestParam(value = "salarySchedule") String salarySchedule) {
        return ResultUtil.makeResult(iDingdingStaffSalaryService.importMonthSalary(file, belong, salarySchedule));
    }

}